 // Storage.js
 //创建封装好的 Storage 对象
 const Storage = {
  // localStorage 操作
  local: {
    get(key) {
      try {
        const value = localStorage.getItem(key)
        return value ? JSON.parse(value) : null
      } catch (error) {
        console.error(`[Storage] Failed to get ${key}:`, error)
        return null
      }
    },
    set(key, value) {
      try {
        localStorage.setItem(key, JSON.stringify(value))
      } catch (error) {
        console.error(`[Storage] Failed to set ${key}:`, error)
      }
    },
    remove(key) {
      localStorage.removeItem(key)
    },
    clear() {
      localStorage.clear()
    }
  },
 
  // sessionStorage 操作
  session: {
    get(key) {
      try {
        const value = sessionStorage.getItem(key)
        return value ? JSON.parse(value) : null
      } catch (error) {
        console.error(`[Storage] Failed to get ${key}:`, error)
        return null
      }
    },
    set(key, value) {
      try {
        sessionStorage.setItem(key, JSON.stringify(value))
      } catch (error) {
        console.error(`[Storage] Failed to set ${key}:`, error)
      }
    },
    remove(key) {
      sessionStorage.removeItem(key)
    },
    clear() {
      sessionStorage.clear()
    }
  }
}

//创建Storage插件
const StoragePlugin = {
  install: (app) => {
    app.config.globalProperties.$storage = Storage;
    app.provide('storage', Storage);
  }
}

//导出Storage对象和插件
export { Storage };
export default  StoragePlugin